using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security;

namespace VRage.Library.Collections
{
	internal static class ThrowHelper
	{
		internal static void ThrowArgumentOutOfRangeException()
		{
			ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
		}

		private static string GetResourceString(string name)
		{
			return name;
		}

		private static string GetResourceString(string name, params object[] args)
		{
			return name;
		}

		internal static void ThrowWrongValueTypeArgumentException(object value, Type targetType)
		{
			throw new ArgumentException(GetResourceString("Arg_WrongType", value, targetType), "value");
		}

		internal static void ThrowKeyNotFoundException()
		{
			throw new KeyNotFoundException();
		}

		internal static void ThrowArgumentException(ExceptionResource resource)
		{
			throw new ArgumentException(GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument)
		{
			throw new ArgumentException(GetResourceString(GetResourceName(resource)), GetArgumentName(argument));
		}

		internal static void ThrowArgumentNullException(ExceptionArgument argument)
		{
			throw new ArgumentNullException(GetArgumentName(argument));
		}

		internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument)
		{
			throw new ArgumentOutOfRangeException(GetArgumentName(argument));
		}

		internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
		{
			throw new ArgumentOutOfRangeException(GetArgumentName(argument), GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowInvalidOperationException(ExceptionResource resource)
		{
			throw new InvalidOperationException(GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowSerializationException(ExceptionResource resource)
		{
			throw new SerializationException(GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowSecurityException(ExceptionResource resource)
		{
			throw new SecurityException(GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowNotSupportedException(ExceptionResource resource)
		{
			throw new NotSupportedException(GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowUnauthorizedAccessException(ExceptionResource resource)
		{
			throw new UnauthorizedAccessException(GetResourceString(GetResourceName(resource)));
		}

		internal static void ThrowObjectDisposedException(string objectName, ExceptionResource resource)
		{
			throw new ObjectDisposedException(objectName, GetResourceString(GetResourceName(resource)));
		}

		internal static void IfNullAndNullsAreIllegalThenThrow<T>(object value, ExceptionArgument argName)
		{
			if (value == null && default(T) != null)
			{
				ThrowArgumentNullException(argName);
			}
		}

		internal static string GetArgumentName(ExceptionArgument argument)
		{
			string text = null;
<<<<<<< HEAD
			switch (argument)
			{
			case ExceptionArgument.array:
				return "array";
			case ExceptionArgument.arrayIndex:
				return "arrayIndex";
			case ExceptionArgument.capacity:
				return "capacity";
			case ExceptionArgument.collection:
				return "collection";
			case ExceptionArgument.list:
				return "list";
			case ExceptionArgument.converter:
				return "converter";
			case ExceptionArgument.count:
				return "count";
			case ExceptionArgument.dictionary:
				return "dictionary";
			case ExceptionArgument.dictionaryCreationThreshold:
				return "dictionaryCreationThreshold";
			case ExceptionArgument.index:
				return "index";
			case ExceptionArgument.info:
				return "info";
			case ExceptionArgument.key:
				return "key";
			case ExceptionArgument.match:
				return "match";
			case ExceptionArgument.obj:
				return "obj";
			case ExceptionArgument.queue:
				return "queue";
			case ExceptionArgument.stack:
				return "stack";
			case ExceptionArgument.startIndex:
				return "startIndex";
			case ExceptionArgument.value:
				return "value";
			case ExceptionArgument.name:
				return "name";
			case ExceptionArgument.mode:
				return "mode";
			case ExceptionArgument.item:
				return "item";
			case ExceptionArgument.options:
				return "options";
			case ExceptionArgument.view:
				return "view";
			case ExceptionArgument.sourceBytesToCopy:
				return "sourceBytesToCopy";
			default:
				return string.Empty;
			}
=======
			return argument switch
			{
				ExceptionArgument.array => "array", 
				ExceptionArgument.arrayIndex => "arrayIndex", 
				ExceptionArgument.capacity => "capacity", 
				ExceptionArgument.collection => "collection", 
				ExceptionArgument.list => "list", 
				ExceptionArgument.converter => "converter", 
				ExceptionArgument.count => "count", 
				ExceptionArgument.dictionary => "dictionary", 
				ExceptionArgument.dictionaryCreationThreshold => "dictionaryCreationThreshold", 
				ExceptionArgument.index => "index", 
				ExceptionArgument.info => "info", 
				ExceptionArgument.key => "key", 
				ExceptionArgument.match => "match", 
				ExceptionArgument.obj => "obj", 
				ExceptionArgument.queue => "queue", 
				ExceptionArgument.stack => "stack", 
				ExceptionArgument.startIndex => "startIndex", 
				ExceptionArgument.value => "value", 
				ExceptionArgument.name => "name", 
				ExceptionArgument.mode => "mode", 
				ExceptionArgument.item => "item", 
				ExceptionArgument.options => "options", 
				ExceptionArgument.view => "view", 
				ExceptionArgument.sourceBytesToCopy => "sourceBytesToCopy", 
				_ => string.Empty, 
			};
>>>>>>> d46cf8619665219cc163a7b28984ced59ed9470d
		}

		internal static string GetResourceName(ExceptionResource resource)
		{
			string text = null;
<<<<<<< HEAD
			switch (resource)
			{
			case ExceptionResource.Argument_ImplementIComparable:
				return "Argument_ImplementIComparable";
			case ExceptionResource.Argument_AddingDuplicate:
				return "Argument_AddingDuplicate";
			case ExceptionResource.ArgumentOutOfRange_BiggerThanCollection:
				return "ArgumentOutOfRange_BiggerThanCollection";
			case ExceptionResource.ArgumentOutOfRange_Count:
				return "ArgumentOutOfRange_Count";
			case ExceptionResource.ArgumentOutOfRange_Index:
				return "ArgumentOutOfRange_Index";
			case ExceptionResource.ArgumentOutOfRange_InvalidThreshold:
				return "ArgumentOutOfRange_InvalidThreshold";
			case ExceptionResource.ArgumentOutOfRange_ListInsert:
				return "ArgumentOutOfRange_ListInsert";
			case ExceptionResource.ArgumentOutOfRange_NeedNonNegNum:
				return "ArgumentOutOfRange_NeedNonNegNum";
			case ExceptionResource.ArgumentOutOfRange_SmallCapacity:
				return "ArgumentOutOfRange_SmallCapacity";
			case ExceptionResource.Arg_ArrayPlusOffTooSmall:
				return "Arg_ArrayPlusOffTooSmall";
			case ExceptionResource.Arg_RankMultiDimNotSupported:
				return "Arg_RankMultiDimNotSupported";
			case ExceptionResource.Arg_NonZeroLowerBound:
				return "Arg_NonZeroLowerBound";
			case ExceptionResource.Argument_InvalidArrayType:
				return "Argument_InvalidArrayType";
			case ExceptionResource.Argument_InvalidOffLen:
				return "Argument_InvalidOffLen";
			case ExceptionResource.Argument_ItemNotExist:
				return "Argument_ItemNotExist";
			case ExceptionResource.InvalidOperation_CannotRemoveFromStackOrQueue:
				return "InvalidOperation_CannotRemoveFromStackOrQueue";
			case ExceptionResource.InvalidOperation_EmptyQueue:
				return "InvalidOperation_EmptyQueue";
			case ExceptionResource.InvalidOperation_EnumOpCantHappen:
				return "InvalidOperation_EnumOpCantHappen";
			case ExceptionResource.InvalidOperation_EnumFailedVersion:
				return "InvalidOperation_EnumFailedVersion";
			case ExceptionResource.InvalidOperation_EmptyStack:
				return "InvalidOperation_EmptyStack";
			case ExceptionResource.InvalidOperation_EnumNotStarted:
				return "InvalidOperation_EnumNotStarted";
			case ExceptionResource.InvalidOperation_EnumEnded:
				return "InvalidOperation_EnumEnded";
			case ExceptionResource.NotSupported_KeyCollectionSet:
				return "NotSupported_KeyCollectionSet";
			case ExceptionResource.NotSupported_ReadOnlyCollection:
				return "NotSupported_ReadOnlyCollection";
			case ExceptionResource.NotSupported_ValueCollectionSet:
				return "NotSupported_ValueCollectionSet";
			case ExceptionResource.NotSupported_SortedListNestedWrite:
				return "NotSupported_SortedListNestedWrite";
			case ExceptionResource.Serialization_InvalidOnDeser:
				return "Serialization_InvalidOnDeser";
			case ExceptionResource.Serialization_MissingKeys:
				return "Serialization_MissingKeys";
			case ExceptionResource.Serialization_NullKey:
				return "Serialization_NullKey";
			case ExceptionResource.Argument_InvalidType:
				return "Argument_InvalidType";
			case ExceptionResource.Argument_InvalidArgumentForComparison:
				return "Argument_InvalidArgumentForComparison";
			case ExceptionResource.InvalidOperation_NoValue:
				return "InvalidOperation_NoValue";
			case ExceptionResource.InvalidOperation_RegRemoveSubKey:
				return "InvalidOperation_RegRemoveSubKey";
			case ExceptionResource.Arg_RegSubKeyAbsent:
				return "Arg_RegSubKeyAbsent";
			case ExceptionResource.Arg_RegSubKeyValueAbsent:
				return "Arg_RegSubKeyValueAbsent";
			case ExceptionResource.Arg_RegKeyDelHive:
				return "Arg_RegKeyDelHive";
			case ExceptionResource.Security_RegistryPermission:
				return "Security_RegistryPermission";
			case ExceptionResource.Arg_RegSetStrArrNull:
				return "Arg_RegSetStrArrNull";
			case ExceptionResource.Arg_RegSetMismatchedKind:
				return "Arg_RegSetMismatchedKind";
			case ExceptionResource.UnauthorizedAccess_RegistryNoWrite:
				return "UnauthorizedAccess_RegistryNoWrite";
			case ExceptionResource.ObjectDisposed_RegKeyClosed:
				return "ObjectDisposed_RegKeyClosed";
			case ExceptionResource.Arg_RegKeyStrLenBug:
				return "Arg_RegKeyStrLenBug";
			case ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck:
				return "Argument_InvalidRegistryKeyPermissionCheck";
			case ExceptionResource.NotSupported_InComparableType:
				return "NotSupported_InComparableType";
			case ExceptionResource.Argument_InvalidRegistryOptionsCheck:
				return "Argument_InvalidRegistryOptionsCheck";
			case ExceptionResource.Argument_InvalidRegistryViewCheck:
				return "Argument_InvalidRegistryViewCheck";
			default:
				return string.Empty;
			}
=======
			return resource switch
			{
				ExceptionResource.Argument_ImplementIComparable => "Argument_ImplementIComparable", 
				ExceptionResource.Argument_AddingDuplicate => "Argument_AddingDuplicate", 
				ExceptionResource.ArgumentOutOfRange_BiggerThanCollection => "ArgumentOutOfRange_BiggerThanCollection", 
				ExceptionResource.ArgumentOutOfRange_Count => "ArgumentOutOfRange_Count", 
				ExceptionResource.ArgumentOutOfRange_Index => "ArgumentOutOfRange_Index", 
				ExceptionResource.ArgumentOutOfRange_InvalidThreshold => "ArgumentOutOfRange_InvalidThreshold", 
				ExceptionResource.ArgumentOutOfRange_ListInsert => "ArgumentOutOfRange_ListInsert", 
				ExceptionResource.ArgumentOutOfRange_NeedNonNegNum => "ArgumentOutOfRange_NeedNonNegNum", 
				ExceptionResource.ArgumentOutOfRange_SmallCapacity => "ArgumentOutOfRange_SmallCapacity", 
				ExceptionResource.Arg_ArrayPlusOffTooSmall => "Arg_ArrayPlusOffTooSmall", 
				ExceptionResource.Arg_RankMultiDimNotSupported => "Arg_RankMultiDimNotSupported", 
				ExceptionResource.Arg_NonZeroLowerBound => "Arg_NonZeroLowerBound", 
				ExceptionResource.Argument_InvalidArrayType => "Argument_InvalidArrayType", 
				ExceptionResource.Argument_InvalidOffLen => "Argument_InvalidOffLen", 
				ExceptionResource.Argument_ItemNotExist => "Argument_ItemNotExist", 
				ExceptionResource.InvalidOperation_CannotRemoveFromStackOrQueue => "InvalidOperation_CannotRemoveFromStackOrQueue", 
				ExceptionResource.InvalidOperation_EmptyQueue => "InvalidOperation_EmptyQueue", 
				ExceptionResource.InvalidOperation_EnumOpCantHappen => "InvalidOperation_EnumOpCantHappen", 
				ExceptionResource.InvalidOperation_EnumFailedVersion => "InvalidOperation_EnumFailedVersion", 
				ExceptionResource.InvalidOperation_EmptyStack => "InvalidOperation_EmptyStack", 
				ExceptionResource.InvalidOperation_EnumNotStarted => "InvalidOperation_EnumNotStarted", 
				ExceptionResource.InvalidOperation_EnumEnded => "InvalidOperation_EnumEnded", 
				ExceptionResource.NotSupported_KeyCollectionSet => "NotSupported_KeyCollectionSet", 
				ExceptionResource.NotSupported_ReadOnlyCollection => "NotSupported_ReadOnlyCollection", 
				ExceptionResource.NotSupported_ValueCollectionSet => "NotSupported_ValueCollectionSet", 
				ExceptionResource.NotSupported_SortedListNestedWrite => "NotSupported_SortedListNestedWrite", 
				ExceptionResource.Serialization_InvalidOnDeser => "Serialization_InvalidOnDeser", 
				ExceptionResource.Serialization_MissingKeys => "Serialization_MissingKeys", 
				ExceptionResource.Serialization_NullKey => "Serialization_NullKey", 
				ExceptionResource.Argument_InvalidType => "Argument_InvalidType", 
				ExceptionResource.Argument_InvalidArgumentForComparison => "Argument_InvalidArgumentForComparison", 
				ExceptionResource.InvalidOperation_NoValue => "InvalidOperation_NoValue", 
				ExceptionResource.InvalidOperation_RegRemoveSubKey => "InvalidOperation_RegRemoveSubKey", 
				ExceptionResource.Arg_RegSubKeyAbsent => "Arg_RegSubKeyAbsent", 
				ExceptionResource.Arg_RegSubKeyValueAbsent => "Arg_RegSubKeyValueAbsent", 
				ExceptionResource.Arg_RegKeyDelHive => "Arg_RegKeyDelHive", 
				ExceptionResource.Security_RegistryPermission => "Security_RegistryPermission", 
				ExceptionResource.Arg_RegSetStrArrNull => "Arg_RegSetStrArrNull", 
				ExceptionResource.Arg_RegSetMismatchedKind => "Arg_RegSetMismatchedKind", 
				ExceptionResource.UnauthorizedAccess_RegistryNoWrite => "UnauthorizedAccess_RegistryNoWrite", 
				ExceptionResource.ObjectDisposed_RegKeyClosed => "ObjectDisposed_RegKeyClosed", 
				ExceptionResource.Arg_RegKeyStrLenBug => "Arg_RegKeyStrLenBug", 
				ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck => "Argument_InvalidRegistryKeyPermissionCheck", 
				ExceptionResource.NotSupported_InComparableType => "NotSupported_InComparableType", 
				ExceptionResource.Argument_InvalidRegistryOptionsCheck => "Argument_InvalidRegistryOptionsCheck", 
				ExceptionResource.Argument_InvalidRegistryViewCheck => "Argument_InvalidRegistryViewCheck", 
				_ => string.Empty, 
			};
>>>>>>> d46cf8619665219cc163a7b28984ced59ed9470d
		}

		public static void ThrowWrongKeyTypeArgumentException(object key, Type type)
		{
			throw new ArgumentException($"Key {key} is not of the correct type.", "key");
		}
	}
}
